/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package gestion;

import impresos.DatosToImprimir;
import impresos.Imp347;
import java.awt.Color;
import java.awt.event.ItemEvent;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.RowFilter;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableRowSorter;
import otros.Excel;
import otros.Fecha;
import otros.MiTableModel;
import otros.Util;
import tablasSql.Compras;
import tablasSql.ConsultaBD;
import tablasSql.FacturasAlbaranes;

/**
 *
 * @author FERRETERIA
 */

public class F347 extends javax.swing.JInternalFrame {    
    boolean fuera;
    int filaSel;
     
    public F347() {
        initComponents();
        tabla.setAutoCreateRowSorter(true);
        tabla.setColumnSelectionAllowed(false);
        String []fecha = new Fecha().getFecha().split("-");
        ch3000.setSelected(true);
        ActualizarTabla();
        Colorear();
    }

    private void Colorear() {
        Color color = Util.getColorTicket(cbTipo.getSelectedItem().toString());
        cbTipo.setBackground(color);
        txtFecha.setBackground(color);
        txtIdCliente.setBackground(color);
    }
    
    private void AnchoColumnas() {
        DefaultTableColumnModel colModel = (DefaultTableColumnModel)tabla.getColumnModel();
        TableColumn col = colModel.getColumn(0);        
        col.setPreferredWidth(25);
        col = colModel.getColumn(2);
        col.setPreferredWidth(25);
    }
    
    private void ActualizarTabla() {  
        int idCliente = Integer.parseInt(txtIdCliente.getText().isEmpty()? "-1" : txtIdCliente.getText());
        String fecha = (txtFecha.getText().isEmpty()) ?  ""+new Fecha().getAño(): txtFecha.getText();
        txtFecha.setText(fecha);
        
        int tam = tabla.getRowCount();
        for (int i = 0; i < tam; i++)
            ((DefaultTableModel)tabla.getModel()).removeRow(0); 
        MiTableModel datos = null;
        if (cbTablas.getSelectedIndex() == 0)
            datos = FacturasAlbaranes.getTabla347(cbTipo.getSelectedIndex(), 
                                              idCliente, fecha);
        else
            datos = Compras.getTabla347(cbTipo.getSelectedIndex(), idCliente, 
                                                    fecha);
        
        tabla.setModel(datos);
        tabla.getColumnModel().getColumn(0).setCellRenderer(new tableCellRender.Texto(filaSel, fuera));
        tabla.getColumnModel().getColumn(1).setCellRenderer(new tableCellRender.Texto(filaSel, fuera));
        tabla.getColumnModel().getColumn(2).setCellRenderer(new tableCellRender.Precio(filaSel, fuera));
        
        TableRowSorter<MiTableModel>modeloOrdenado = new TableRowSorter<MiTableModel>(datos);
        tabla.setRowSorter(modeloOrdenado);
        // intervalo de busqueda 
        double valor;
        valor = 3005.5999;
        ch3000.setText(">3005.60");
            
        if (ch3000.isSelected()) {
            modeloOrdenado.setRowFilter(RowFilter.numberFilter(RowFilter.ComparisonType.AFTER, valor, 2));
        }    
        else {
            modeloOrdenado.setRowFilter(null);
        }
        //----
        AnchoColumnas();
        HallarTotal();
    }
    
    
    private void HallarTotal() {
        float total = 0;
        for(int i = 0; i < tabla.getRowCount(); i++) {
            total += Float.parseFloat(tabla.getValueAt(i, 2).toString());
        }
        txtTotal.setText(Util.getFormatPrecio(total,2));
    }
    
    private void VerTrimestres(String cod) {
        Float [] tri = FacturasAlbaranes.getTrimestres(cbTipo.getSelectedIndex(), cod, txtFecha.getText());
        if (tri != null) {
            t1.setText(Util.getFormatPrecio(tri[0], 2));
            t2.setText(Util.getFormatPrecio(tri[1], 2));
            t3.setText(Util.getFormatPrecio(tri[2], 2));
            t4.setText(Util.getFormatPrecio(tri[3], 2));
        } else {
            t1.setText("Error");
            t2.setText("Error");
            t3.setText("Error");
            t4.setText("Error");
        }          
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jScrollPane1 = new javax.swing.JScrollPane();
        tabla = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        cbTipo = new javax.swing.JComboBox();
        txtIdCliente = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        bBuscar = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        cbTablas = new javax.swing.JComboBox();
        txtFecha = new javax.swing.JTextField();
        ch3000 = new javax.swing.JCheckBox();
        jPanel2 = new javax.swing.JPanel();
        t1 = new javax.swing.JTextField();
        t2 = new javax.swing.JTextField();
        t3 = new javax.swing.JTextField();
        t4 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        bExcel = new javax.swing.JButton();
        bImprimir = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        txtTotal = new javax.swing.JTextField();

        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Datos para el 347");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/img/icono2.png"))); // NOI18N
        addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formKeyPressed(evt);
            }
        });
        getContentPane().setLayout(new java.awt.GridBagLayout());

        jScrollPane1.setMinimumSize(new java.awt.Dimension(250, 250));
        jScrollPane1.setPreferredSize(new java.awt.Dimension(250, 250));

        tabla.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Cliente", "Total"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabla.setColumnSelectionAllowed(true);
        tabla.getTableHeader().setReorderingAllowed(false);
        tabla.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                tablaMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                tablaMouseExited(evt);
            }
        });
        tabla.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                tablaMouseMoved(evt);
            }
        });
        jScrollPane1.setViewportView(tabla);
        tabla.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        if (tabla.getColumnModel().getColumnCount() > 0) {
            tabla.getColumnModel().getColumn(0).setResizable(false);
            tabla.getColumnModel().getColumn(1).setResizable(false);
        }

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        getContentPane().add(jScrollPane1, gridBagConstraints);

        jPanel1.setMinimumSize(new java.awt.Dimension(400, 70));
        jPanel1.setPreferredSize(new java.awt.Dimension(400, 70));
        jPanel1.setLayout(new java.awt.GridBagLayout());

        jLabel1.setText("Criterios de busqueda:   ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
        jPanel1.add(jLabel1, gridBagConstraints);

        cbTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Factura", "Albaran" }));
        cbTipo.setMinimumSize(new java.awt.Dimension(100, 20));
        cbTipo.setPreferredSize(new java.awt.Dimension(100, 20));
        cbTipo.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbTipoItemStateChanged(evt);
            }
        });
        cbTipo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                cbTipoKeyPressed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 0);
        jPanel1.add(cbTipo, gridBagConstraints);

        txtIdCliente.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtIdCliente.setMinimumSize(new java.awt.Dimension(100, 20));
        txtIdCliente.setPreferredSize(new java.awt.Dimension(40, 20));
        txtIdCliente.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtIdClienteMouseClicked(evt);
            }
        });
        txtIdCliente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtIdClienteKeyPressed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
        jPanel1.add(txtIdCliente, gridBagConstraints);

        jLabel6.setText("Id Cliente");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 5);
        jPanel1.add(jLabel6, gridBagConstraints);

        bBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/buscar.png"))); // NOI18N
        bBuscar.setMinimumSize(new java.awt.Dimension(61, 61));
        bBuscar.setPreferredSize(new java.awt.Dimension(61, 61));
        bBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bBuscarActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 10;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridheight = 3;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
        jPanel1.add(bBuscar, gridBagConstraints);

        jLabel4.setText("Año");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
        jPanel1.add(jLabel4, gridBagConstraints);

        cbTablas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Ventas", "Compras" }));
        cbTablas.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbTablasItemStateChanged(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 3, 0);
        jPanel1.add(cbTablas, gridBagConstraints);

        txtFecha.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtFecha.setMinimumSize(new java.awt.Dimension(80, 20));
        txtFecha.setPreferredSize(new java.awt.Dimension(80, 20));
        txtFecha.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtFechaKeyReleased(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
        jPanel1.add(txtFecha, gridBagConstraints);

        ch3000.setText(">3000€");
        ch3000.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ch3000ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 2;
        jPanel1.add(ch3000, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.ipadx = 175;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 10, 0, 10);
        getContentPane().add(jPanel1, gridBagConstraints);

        jPanel2.setOpaque(false);
        jPanel2.setPreferredSize(new java.awt.Dimension(300, 60));
        jPanel2.setLayout(new java.awt.GridBagLayout());

        t1.setEditable(false);
        t1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        t1.setPreferredSize(new java.awt.Dimension(70, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridy = 1;
        jPanel2.add(t1, gridBagConstraints);

        t2.setEditable(false);
        t2.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        t2.setPreferredSize(new java.awt.Dimension(70, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 0);
        jPanel2.add(t2, gridBagConstraints);

        t3.setEditable(false);
        t3.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        t3.setPreferredSize(new java.awt.Dimension(70, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 0);
        jPanel2.add(t3, gridBagConstraints);

        t4.setEditable(false);
        t4.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        t4.setPreferredSize(new java.awt.Dimension(70, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 0);
        jPanel2.add(t4, gridBagConstraints);

        jLabel2.setText("Trimestre 1");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        jPanel2.add(jLabel2, gridBagConstraints);

        jLabel3.setText("Trimestre 2");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        jPanel2.add(jLabel3, gridBagConstraints);

        jLabel5.setText("Trimestre 3");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        jPanel2.add(jLabel5, gridBagConstraints);

        jLabel7.setText("Trimestre 4");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        jPanel2.add(jLabel7, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 0);
        getContentPane().add(jPanel2, gridBagConstraints);

        jPanel3.setPreferredSize(new java.awt.Dimension(130, 60));
        jPanel3.setLayout(new java.awt.GridBagLayout());

        bExcel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/Excel2.png"))); // NOI18N
        bExcel.setMaximumSize(new java.awt.Dimension(71, 71));
        bExcel.setMinimumSize(new java.awt.Dimension(60, 60));
        bExcel.setPreferredSize(new java.awt.Dimension(60, 60));
        bExcel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bExcelActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
        jPanel3.add(bExcel, gridBagConstraints);

        bImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/imprimir.png"))); // NOI18N
        bImprimir.setToolTipText("Imprimir");
        bImprimir.setMaximumSize(new java.awt.Dimension(60, 60));
        bImprimir.setMinimumSize(new java.awt.Dimension(60, 60));
        bImprimir.setName("bImprimir"); // NOI18N
        bImprimir.setPreferredSize(new java.awt.Dimension(70, 70));
        bImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bImprimirActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        jPanel3.add(bImprimir, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 10);
        getContentPane().add(jPanel3, gridBagConstraints);

        jPanel4.setMinimumSize(new java.awt.Dimension(100, 80));
        jPanel4.setPreferredSize(new java.awt.Dimension(130, 60));
        jPanel4.setLayout(new java.awt.GridBagLayout());

        jLabel11.setText("Total");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        jPanel4.add(jLabel11, gridBagConstraints);

        txtTotal.setEditable(false);
        txtTotal.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtTotal.setMinimumSize(new java.awt.Dimension(100, 20));
        txtTotal.setPreferredSize(new java.awt.Dimension(100, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        jPanel4.add(txtTotal, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 0);
        getContentPane().add(jPanel4, gridBagConstraints);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == 34) {
            int i = cbTipo.getSelectedIndex();
            if (i > cbTipo.getItemCount()) 
               i = 0;
            else
                i++;
            cbTipo.setSelectedIndex(i);
        }
    }//GEN-LAST:event_formKeyPressed

    private void cbTipoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cbTipoKeyPressed
        if (evt.getKeyCode() == 10) 
            cbTipo.transferFocus();
    }//GEN-LAST:event_cbTipoKeyPressed

    private void tablaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaMouseClicked
        int fila = tabla.rowAtPoint(evt.getPoint());
        int columna = tabla.columnAtPoint(evt.getPoint());
        
        VerTrimestres(""+tabla.getValueAt(fila, 0));
    }//GEN-LAST:event_tablaMouseClicked

    private void txtIdClienteKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtIdClienteKeyPressed
        switch (evt.getKeyCode()) {
            case 113:
                FClientes c = new FClientes(this, Util.FFACTURAS);
                this.getParent().add(c);
                Principal.centrarFrame(c);
                c.show();
                break;
            case 10:
                ActualizarTabla();
                break;
        }
    }//GEN-LAST:event_txtIdClienteKeyPressed

    private void tablaMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaMouseExited
        fuera = true;
    }//GEN-LAST:event_tablaMouseExited

    private void tablaMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaMouseEntered
        fuera = false;
    }//GEN-LAST:event_tablaMouseEntered

    private void tablaMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaMouseMoved
        JTable aTable =  (JTable)evt.getSource();
        if (!fuera) {
            filaSel = aTable.rowAtPoint(evt.getPoint());
        }
    }//GEN-LAST:event_tablaMouseMoved

    private void bBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bBuscarActionPerformed
        ActualizarTabla();
    }//GEN-LAST:event_bBuscarActionPerformed

    private void txtIdClienteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtIdClienteMouseClicked
        txtIdCliente.selectAll();
    }//GEN-LAST:event_txtIdClienteMouseClicked

    private void cbTipoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbTipoItemStateChanged
        if (evt.getStateChange() == ItemEvent.SELECTED) {
            ActualizarTabla();
            Colorear();
        }
    }//GEN-LAST:event_cbTipoItemStateChanged

    private void cbTablasItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbTablasItemStateChanged
        if (evt.getStateChange() == ItemEvent.SELECTED) {
            ActualizarTabla();
        }
    }//GEN-LAST:event_cbTablasItemStateChanged

    private void txtFechaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtFechaKeyReleased
        if (evt.getKeyCode() == 10) {
            ActualizarTabla();
        }
    }//GEN-LAST:event_txtFechaKeyReleased

    private void bExcelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bExcelActionPerformed
        ConsultaBD.cursorEspera(this);
        Excel.Exportar347(tabla, cbTipo.getSelectedIndex(), txtFecha.getText());
        ConsultaBD.cursorNormal(this);
    }//GEN-LAST:event_bExcelActionPerformed

    private void ch3000ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ch3000ActionPerformed
        ActualizarTabla();
    }//GEN-LAST:event_ch3000ActionPerformed

    private void bImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bImprimirActionPerformed
        int op = JOptionPane.showOptionDialog(this, "¿Imprimir en PDF?", "Seleccione opcion", 
                            JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE, null,
                            new Object[] { "Si", "No" }, 
                            "Si"); 
        if (op != -1) {
            ConsultaBD.cursorEspera(this);
            DatosToImprimir objP = new DatosToImprimir();
            objP.setTabla(tabla);
            objP.setFecha(txtFecha.getText());
            objP.setTipoTicket(""+cbTipo.getSelectedIndex());
            Imp347.imprime((op == 0) ? true: false, objP);
            ConsultaBD.cursorNormal(this);
        }
    }//GEN-LAST:event_bImprimirActionPerformed

         
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bBuscar;
    private javax.swing.JButton bExcel;
    private javax.swing.JButton bImprimir;
    private javax.swing.JComboBox cbTablas;
    private javax.swing.JComboBox cbTipo;
    private javax.swing.JCheckBox ch3000;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField t1;
    private javax.swing.JTextField t2;
    private javax.swing.JTextField t3;
    private javax.swing.JTextField t4;
    private javax.swing.JTable tabla;
    private javax.swing.JTextField txtFecha;
    public javax.swing.JTextField txtIdCliente;
    private javax.swing.JTextField txtTotal;
    // End of variables declaration//GEN-END:variables
}
